package com.qq.weixin.mp.bean;

import java.util.Calendar;

import com.qq.weixin.mp.aes.AesException;
import com.qq.weixin.mp.aes.SHA1;
import com.qq.weixin.mp.aes.WXBizMsgCrypt;
import com.soecode.wxtools.util.StringUtils;
import com.soecode.wxtools.util.xml.XStreamCDataConverter;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;

/**
 * <pre>
 * 被动回复消息--回复文本消息体
 * 
 * 详情:http://mp.weixin.qq.com/wiki/1/6239b44c206cab9145b1d52c67e6c551.html
 * </pre>
 * @author antgan
 *
 */
@XStreamAlias("xml")
public class QyWxXmlResponseBody {

	@XStreamAlias("Encrypt")
	@XStreamConverter(value = XStreamCDataConverter.class)
	protected String encrypt;
	

	@XStreamAlias("MsgSignature")
	@XStreamConverter(value = XStreamCDataConverter.class)
	protected String msgSignature;
	

	@XStreamAlias("TimeStamp")
	@XStreamConverter(value = XStreamCDataConverter.class)
	protected String timeStamp;

	@XStreamAlias("Nonce")
	@XStreamConverter(value = XStreamCDataConverter.class)
	protected String nonce;
	
	public QyWxXmlResponseBody makeResponse(WXBizMsgCrypt cryptor, String replyMsg) throws AesException {
		nonce = StringUtils.randomStr(10);
		timeStamp = Long.toString(Calendar.getInstance().getTimeInMillis());
		encrypt = cryptor.EncryptMsg(replyMsg, timeStamp, nonce);
		msgSignature = SHA1.getSHA1("", timeStamp, nonce, encrypt);
		return this;
		
	}
	
	@Override
	public String toString() {
		return "QyWxXmlTextResponseBody [encrypt=" + encrypt +
				", msgSignature=" + msgSignature +
				", timeStamp=" + timeStamp +
				", nonce=" + nonce +
				"]";
	}

	public String getEncrypt() {
		return encrypt;
	}

	public void setEncrypt(String encrypt) {
		this.encrypt = encrypt;
	}

	public String getMsgSignature() {
		return msgSignature;
	}

	public void setMsgSignature(String msgSignature) {
		this.msgSignature = msgSignature;
	}

	public String getTimeStamp() {
		return timeStamp;
	}

	public void setTimeStamp(String timeStamp) {
		this.timeStamp = timeStamp;
	}

	public String getNonce() {
		return nonce;
	}

	public void setNonce(String nonce) {
		this.nonce = nonce;
	}

	
}
